home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 60 / IOPROG_60.ISO / soft / c++ / gsl-1.1.1-setup.exe / {app} / src / histogram / test_trap.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-08-22  |  4.1 KB  |  133 lines

  1. /* histogram/test_trap.c
  2.  * 
  3.  * Copyright (C) 1996, 1997, 1998, 1999, 2000 Brian Gough
  4.  * 
  5.  * This program is free software; you can redistribute it and/or modify
  6.  * it under the terms of the GNU General Public License as published by
  7.  * the Free Software Foundation; either version 2 of the License, or (at
  8.  * your option) any later version.
  9.  * 
  10.  * This program is distributed in the hope that it will be useful, but
  11.  * WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13.  * General Public License for more details.
  14.  * 
  15.  * You should have received a copy of the GNU General Public License
  16.  * along with this program; if not, write to the Free Software
  17.  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  */
  19.  
  20. #include <config.h>
  21. #include <stdlib.h>
  22. #include <stdio.h>
  23. #include <gsl/gsl_histogram.h>
  24. #include <gsl/gsl_test.h>
  25. #include <gsl/gsl_errno.h>
  26. #include <gsl/gsl_ieee_utils.h>
  27.  
  28. #define N 397
  29.  
  30. void my_error_handler (const char *reason, const char *file,
  31.                int line, int err);
  32. int status = 0;
  33.  
  34. int
  35. main (void)
  36. {
  37.   gsl_histogram *h;
  38.   double result, lower, upper;
  39.   size_t i;
  40.  
  41.   gsl_set_error_handler (&my_error_handler);
  42.  
  43.   gsl_ieee_env_setup ();
  44.  
  45.   status = 0;
  46.   h = gsl_histogram_calloc (0);
  47.   gsl_test (!status, "gsl_histogram_calloc traps zero-length histogram");
  48.   gsl_test (h != 0,
  49.         "gsl_histogram_calloc returns NULL for zero-length histogram");
  50.  
  51.   status = 0;
  52.   h = gsl_histogram_calloc_uniform (0, 0.0, 1.0);
  53.   gsl_test (!status,
  54.         "gsl_histogram_calloc_uniform traps zero-length histogram");
  55.   gsl_test (h != 0,
  56.      "gsl_histogram_calloc_uniform returns NULL for zero-length histogram");
  57.  
  58.   status = 0;
  59.   h = gsl_histogram_calloc_uniform (10, 1.0, 1.0);
  60.   gsl_test (!status,
  61.         "gsl_histogram_calloc_uniform traps equal endpoints");
  62.   gsl_test (h != 0,
  63.         "gsl_histogram_calloc_uniform returns NULL for equal endpoints");
  64.  
  65.   status = 0;
  66.   h = gsl_histogram_calloc_uniform (10, 2.0, 1.0);
  67.   gsl_test (!status,
  68.         "gsl_histogram_calloc_uniform traps invalid range");
  69.   gsl_test (h != 0,
  70.         "gsl_histogram_calloc_uniform returns NULL for invalid range");
  71.  
  72.   h = gsl_histogram_calloc_uniform (N, 0.0, 1.0);
  73.  
  74.   status = gsl_histogram_accumulate (h, 1.0, 10.0);
  75.   gsl_test (status != GSL_EDOM, "gsl_histogram_accumulate traps x at xmax");
  76.  
  77.   status = gsl_histogram_accumulate (h, 2.0, 100.0);
  78.   gsl_test (status != GSL_EDOM, "gsl_histogram_accumulate traps x above xmax");
  79.  
  80.   status = gsl_histogram_accumulate (h, -1.0, 1000.0);
  81.   gsl_test (status != GSL_EDOM, "gsl_histogram_accumulate traps x below xmin");
  82.  
  83.   status = gsl_histogram_increment (h, 1.0);
  84.   gsl_test (status != GSL_EDOM, "gsl_histogram_increment traps x at xmax");
  85.  
  86.   status = gsl_histogram_increment (h, 2.0);
  87.   gsl_test (status != GSL_EDOM, "gsl_histogram_increment traps x above xmax");
  88.  
  89.   status = gsl_histogram_increment (h, -1.0);
  90.   gsl_test (status != GSL_EDOM, "gsl_histogram_increment traps x below xmin");
  91.  
  92.  
  93.   result = gsl_histogram_get (h, N);
  94.   gsl_test (result != 0, "gsl_histogram_get traps index at n");
  95.  
  96.   result = gsl_histogram_get (h, N + 1);
  97.   gsl_test (result != 0, "gsl_histogram_get traps index above n");
  98.  
  99.   status = gsl_histogram_get_range (h, N, &lower, &upper);
  100.   gsl_test (status != GSL_EDOM,
  101.         "gsl_histogram_get_range traps index at n");
  102.  
  103.   status = gsl_histogram_get_range (h, N + 1, &lower, &upper);
  104.   gsl_test (status != GSL_EDOM,
  105.         "gsl_histogram_get_range traps index above n");
  106.  
  107.  
  108.   status = 0;
  109.   gsl_histogram_find (h, -0.01, &i);
  110.   gsl_test (status != GSL_EDOM, "gsl_histogram_find traps x below xmin");
  111.  
  112.   status = 0;
  113.   gsl_histogram_find (h, 1.0, &i);
  114.   gsl_test (status != GSL_EDOM, "gsl_histogram_find traps x at xmax");
  115.  
  116.   status = 0;
  117.   gsl_histogram_find (h, 1.1, &i);
  118.   gsl_test (status != GSL_EDOM, "gsl_histogram_find traps x above xmax");
  119.  
  120.   gsl_histogram_free (h);
  121.  
  122.   exit (gsl_test_summary ());
  123. }
  124.  
  125.  
  126. void
  127. my_error_handler (const char *reason, const char *file, int line, int err)
  128. {
  129.   if (0)
  130.     printf ("(caught [%s:%d: %s (%d)])\n", file, line, reason, err);
  131.   status = 1;
  132. }
  133.